// src/stores/routeStore.ts
import { defineStore } from 'pinia'
import { RouteRecordRaw } from 'vue-router'

interface RouteState {
  cachedRoutes: RouteRecordRaw[]
  lastFetchTime: number
}

export const useRouteStore = defineStore('route', {
  state: (): RouteState => ({
    cachedRoutes: [],
    lastFetchTime: 0
  }),
  actions: {
    setRoutes(routes: RouteRecordRaw[]) {
      this.cachedRoutes = routes
      this.lastFetchTime = Date.now()
    },
    clearCache() {
      this.cachedRoutes = []
      this.lastFetchTime = 0
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'route_cache',
        storage: localStorage,
        paths: ['cachedRoutes', 'lastFetchTime']
      }
    ]
  }
})